﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.IO;

namespace Gemciler_Uretim
{
    public partial class ParamsTanimla : DevExpress.XtraEditors.XtraForm
    {
        public ParamsTanimla()
        {
            InitializeComponent();
        }
        public Int32 kullanici_kodu, params_no;
       public string aciklama,user_skin_ismi,params_ekleme_tipi;
        Int32 par_int;
        double par_float;
        string par_string;

        string AppPath = System.Windows.Forms.Application.StartupPath;
        DateTime par_date;


        SqlConnecitonClass sqlbaglanti = new SqlConnecitonClass();

        private void simpleButton1_Click(object sender, EventArgs e)
        {
          
           string  pardate="20120101";
           params_no = Convert.ToInt32(text_paramsno.Text);
            string float_alan=par_t_float.Text.Replace(",",".");
                float_alan="0";
                int aktif = 1;
                par_string = bolum_cb.EditValue.ToString();

               // MessageBox.Show(bolum_cb.EditValue.ToString());

            if (params_ekleme_tipi == "par_var")
                {
                    par_string = par_t_var.Text;
                }
    
           sqlbaglanti.CommScalar("DELETE FROM TK_PARAMS WHERE params_no ="+params_no+" and par_kullanici="+kullanici_kodu+"",CommandType.Text);
               sqlbaglanti.CommScalar("INSERT INTO [TK_PARAMS]           ([params_no]       ,[par_kullanici]      ,[par_int]"
         +  ",[par_var]      ,[par_float]       ,[par_date]      ,[par_bit]       ,[par_aciklama])"
            + " VALUES ("+params_no+","+kullanici_kodu+",0,'"+ par_string+"' ,0,'',0,'"+text_aciklama.Text+"')",CommandType.Text);

            Close();

        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            Close();

        }

        private void ParamsTanimla_Load(object sender, EventArgs e)
        {
            if (params_ekleme_tipi == "par_var")
            {
                bolum_cb.Visible = false;
                par_t_var.Visible = true;
                label_var.Visible = true;
            }

         
            DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName = user_skin_ismi;
            DevExpress.Skins.SkinManager.EnableFormSkins();

            text_aciklama.Text = aciklama;
            text_paramsno.Text =Convert.ToString( params_no);
            

            par_t_var.Text = Convert.ToString(sqlbaglanti.CommScalar("select dbo.tk_par_var('"+kullanici_kodu+"',"+params_no+")", CommandType.Text));
         //   par_t_date.Text = Convert.ToString(sqlbaglanti.CommScalar("select dbo.tk_par_date('" + kullanici_kodu + "'," + params_no + ")", CommandType.Text));
       //     par_t_float.Text = Convert.ToString(sqlbaglanti.CommScalar("select dbo.tk_par_float('" + kullanici_kodu + "'," + params_no + ")", CommandType.Text));
            par_t_int.Text = Convert.ToString(sqlbaglanti.CommScalar("select dbo.tk_par_int('" + kullanici_kodu + "'," + params_no + ")", CommandType.Text));

            if (params_no > 0)
            {
                
                text_paramsno.Enabled = false;
            }
            if (params_ekleme_tipi == "personel")
            {

                bolum_cb.Properties.DataSource = sqlbaglanti.ShowTable("SELECT cari_per_kod AS KOD , cari_per_adi+cari_per_soyadi AS AD from CARI_PERSONEL_TANIMLARI ", CommandType.Text);
                bolum_cb.Properties.ValueMember = "KOD";
                bolum_cb.Properties.DisplayMember = "AD";
                bolum_cb.Visible = true;
                bolum_label.Visible = true;
                text_paramsno.Text = "21";
                text_paramsno.Enabled = false;
                text_aciklama.Enabled = false;
            }
            if (params_ekleme_tipi == "bölüm")
            {

                bolum_cb.Properties.DataSource = sqlbaglanti.ShowTable("select bolum_no AS KOD ,bolum_adi AS [AD] FROM TK_URT_BOLUM_TANIMLARI  ORDER BY bolum_no", CommandType.Text);
                bolum_cb.Properties.ValueMember = "KOD";
                bolum_cb.Properties.DisplayMember = "AD";

                bolum_cb.Visible = true;
                bolum_label.Visible = true;
                text_paramsno.Text = "20";
                text_paramsno.Enabled = false;
                text_aciklama.Enabled = false;

            } 
           
        
        }

      

        private void simpleButton1_Click_1(object sender, EventArgs e)
        {
            if (File.Exists("" + AppPath + "\\SISTEM\\Params_no.txt"))
            {
                StreamReader sr = File.OpenText("" + AppPath + "\\SISTEM\\Params_no.txt");
                string okunan = Convert.ToString(sr.ReadToEnd());  //1 SATIR

                sr.Close();
                MessageBox.Show("" + okunan + "");
            }
            else
            {
                MessageBox.Show("\\SISTEM\\Params_no.txt BULUNAMADI "); Close();
            }

        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Secili Kayıt ", "Silme Onayı Verin", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {

                sqlbaglanti.CommScalar("DELETE FROM TK_PARAMS WHERE params_no =" + params_no + " and par_kullanici=" + kullanici_kodu + "", CommandType.Text);
                Close();
            }
        }

        private void buttonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            //KayitSecim fr = new KayitSecim();
            //fr.sorgu = "SELECT [par_params] AS [KODU]  ,[par_params_ad] AS [ADI]  FROM [TK_PARAMS_LIST]";
            //fr.ShowDialog();
            //text_paramsno.Text = fr.secilen_kod;
            //text_aciklama.Text = fr.secilen_adi;
        }

        private void bolum_cb_EditValueChanged(object sender, EventArgs e)
        {
            text_aciklama.Text = bolum_cb.Text;
        }
    }
}